#region License and Copyright

/*
 * Copyright (C) 2008 Nathan Palmer
 * http://www.nathanpalmer.com
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Author:
 *     Nathan Palmer <nathan1@nathanpalmer.com>
 */

#endregion

using System;
using System.Collections.Generic;
using System.Text;

namespace AmazonS3Explorer
{
    public class FileHelper
    {
        private static readonly long kilobyte = 1024;
        private static readonly long megabyte = 1024 * kilobyte;
        private static readonly long gigabyte = 1024 * megabyte;
        private static readonly long terabyte = 1024 * gigabyte;

        public static string ToByteString(long bytes)
        {
            if (bytes > terabyte) return (bytes / terabyte).ToString("0.00 TB");
            else if (bytes > gigabyte) return (bytes / gigabyte).ToString("0.00 GB");
            else if (bytes > megabyte) return (bytes / megabyte).ToString("0.00 MB");
            else if (bytes > kilobyte) return (bytes / kilobyte).ToString("0.00 KB");
            else return bytes + " Bytes";
        }
    }
}
